﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WanMeiBussinessService;
using WanMeiCommon;
using WanMeiModel;

namespace WanMeiService
{
    public class MainController
    {
        //private static IUserService _IUserSerivce = BussinessFactory.CreateInstance<IUserService>("UserService");
        private static IRoleService _IRoleService = BussinessFactory.CreateInstance<IRoleService>("RoleService");
        /// <summary>
        /// 获取连接信息
        /// </summary>
        /// <param name="un"></param>
        /// <param name="heroId"></param>
        /// <returns></returns>
        public UserInfoModel CreateConnected(string un, int heroId)
        {
            UserInfoModel result = null;
            if (string.IsNullOrEmpty(un) || heroId <= 0)
            {
                return null;
            }
            result = RedisManager.Get<UserInfoModel>("CreateConnected_"+un+"_"+heroId);
            if (result == null)
            {
                result = _IRoleService.GetUserInfoModel(un, heroId);
                if (result != null)
                {
                    RedisManager.Set<UserInfoModel>("CreateConnected_" + un + "_" + heroId, result, DateTime.Now.AddHours(24));
                }
            }

            return result;
        }
        /// <summary>
        /// 异步写入聊天消息日志
        /// </summary>
        /// <param name="model"></param>
        public void WriteChatLog(ChatLogModel model)
        {
            Task.Factory.StartNew(() =>
            {
                _IRoleService.WriteChatLog(model);
            });
        }
    }
}
